package com.hex.liyue.usermodule.presenter;

import com.hex.liyue.commonmodule.bean.BaseBean;
import com.hex.liyue.commonmodule.manager.HttpManager;
import com.hex.liyue.commonmodule.manager.UserManager;
import com.hex.liyue.commonmodule.net.ResponseListener;
import com.hex.liyue.usermodule.bean.OrderDetailsResultBean;

/**
 * Created by WJ on 2016/6/29.
 */
public class OrderDetailsPresenter {
    private IOrderDetailsView iOrderDetailsView;

    public OrderDetailsPresenter(IOrderDetailsView iOrderDetailsView) {
        this.iOrderDetailsView = iOrderDetailsView;
    }

    public void getOrderDetails(String orderId) {
        iOrderDetailsView.showLod("加载中...");
        HttpManager.getInstance().orders_detail(UserManager.getUserId(), orderId, new ResponseListener<OrderDetailsResultBean>() {
            @Override
            public void onSuccess(OrderDetailsResultBean orderDetailsResultBean) {
                iOrderDetailsView.closeLod();
                iOrderDetailsView.setInfo(orderDetailsResultBean.data);
            }

            @Override
            public void onFailure(String responseresult) {
                iOrderDetailsView.closeLod();
                iOrderDetailsView.showT(responseresult);
            }
        });
    }

    public void cancelOrder(final String order_id) {
        iOrderDetailsView.showLod("加载中...");
        HttpManager.getInstance().orders_cancel(UserManager.getUserId(), order_id, new ResponseListener<BaseBean>() {
            @Override
            public void onSuccess(BaseBean baseBean) {
                iOrderDetailsView.closeLod();
                getOrderDetails(order_id);
            }

            @Override
            public void onFailure(String responseresult) {
                iOrderDetailsView.closeLod();
                iOrderDetailsView.showT(responseresult);
            }
        });
    }
}
